<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2019/3/22
 * Time: 11:01
 */
namespace Modules\ApiV2\Controllers;
use App\Models\Configure;
use App\Models\JrttEquipment;
use Illuminate\Http\Request;
use Modules\Service\Logic\HomeLogic;
use EasyWeChat\Factory;

class HomeController extends BaseController{
    //首页接口
    public function index(Request $request){
        $platform = $request->header("app-platform");
        $version = $request->header("app-version");
        return HomeLogic::home($platform,$version);
    }

    //弹窗
    public function popups(){
        return self::success(config('dialog.window'));
    }


    //分享
    public function share(){
        $data = [
            'share_title' => Configure::getByKey('share_title'),
            'share_desc'  => Configure::getByKey('share_desc'),
            'share_img'   => Configure::getByKey('share_img'),
            'share_link'  => Configure::getByKey('share_link')
        ];

        return success($data);
    }

    //分享
    public function qingming(){
        $data = [
            'share_title' => "清明踏青,惠有壕礼",
            'share_desc'  => "立即助力好友，一起抽取百元油卡、30元话费等奖励！",
            'share_img'   => "http://download.jiayouhui360.com/qingming2019.png",
            'share_link'  => "http://h5.wenhuakj.com/lottery"
        ];

        return success($data);
    }

    public function jssdk(Request $request)
    {
        $app  = Factory::officialAccount(config('wechat'));
        $APIs = [
            'updateAppMessageShareData',
            'updateTimelineShareData',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'closeWindow',
            'onMenuShareAppMessage',
            'onMenuShareTimeline',
            'showMenuItems',
            'openAddress',
            'chooseWXPay',
            'getLocation',
            'scanQRCode',
            'chooseImage',
            'previewImage',
            'uploadImage'
        ];
        $url = $request->input('url',false);
        if (!$url)return self::fail(1003,"缺少必要参数:url");
        $sdkUrl = explode('#',urldecode($url))[0];
        $app->jssdk->setUrl($sdkUrl);
        $data = $app->jssdk->buildConfig($APIs, $debug = false, $beta = false, $json = false);

        return success($data);
    }

    //发现页导航
    public function discover(Request $request)
    {
        $platform = $request->header("app-platform");
        $version = $request->header("app-version");
        $result = HomeLogic::discover($platform,$version);
        return self::success($result);
    }
}